//
//  WBLoginView.m
//  OC版新浪微博
//
//  Created by chenguanglei on 16/12/3.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "WBLoginView.h"
#import "WBAddition.h"

#define loginMagin 10
#define buttonW 100
#define buttonH 35

@interface WBLoginView ()

@property(nonatomic,weak) UIImageView *iconImageView;
@property(nonatomic,weak) UILabel *messageLabel;
@property(nonatomic,weak) UIImageView *animationView;

@end

@implementation WBLoginView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}


- (void)iconImage:(nonnull NSString *)iconImage message:(nonnull NSString *)messageTitle isAnimation:(BOOL)isHidden{

    _iconImageView.image = [UIImage imageNamed:iconImage];
    _messageLabel.text = messageTitle;
    [_animationView setHidden:isHidden];
}


- (void)setupUI{

    self.backgroundColor = [UIColor yellowColor];
    
    UIImageView *iconImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_image_message"]];
    
    [self addSubview:iconImageView];
    
    
    UILabel *messageLabel = [UILabel text:@"登陆后,别人评论的你的微博,发给你的消息,都会在这里收到通知" size:14 textColor:[UIColor lightGrayColor] textAlignment:NSTextAlignmentCenter isSingleLine:NO];
    
    
    [self addSubview:messageLabel];
    
    
    UIButton *registerButton = [UIButton buttonTitle:@"注册" titleColor:[UIColor darkGrayColor] titleSize:14 normalImage:nil bgImage:@"common_button_white_disable" corner:5];
    
    registerButton.tag = 0;
    
    [self addSubview:registerButton];
    
    
    UIButton *loginButton = [UIButton buttonTitle:@"登陆" titleColor:[UIColor darkGrayColor] titleSize:14 normalImage:nil bgImage:@"common_button_white_disable" corner:5];
    
    loginButton.tag = 1;
    
    [self addSubview:loginButton];
    
    
    UIImageView *animationView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    
    [self addSubview:animationView];
    
    
    
    [animationView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    
    
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(animationView.mas_bottom).offset(loginMagin);
        make.width.mas_equalTo(220);
    }];
    

    [registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(messageLabel);
        make.top.equalTo(messageLabel.mas_bottom).offset(loginMagin);
        make.width.mas_equalTo(buttonW);
        make.height.mas_equalTo(buttonH);
    }];
    

    [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(messageLabel);
        make.top.equalTo(messageLabel.mas_bottom).offset(loginMagin);
        make.width.mas_equalTo(buttonW);
        make.height.mas_equalTo(buttonH);
    }];
    

    [registerButton addTarget:self action:@selector(registerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [loginButton addTarget:self action:@selector(loginButonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _iconImageView = iconImageView;
    _messageLabel = messageLabel;
    _animationView = animationView;
    
}


//注册按钮点击事件
- (void)registerButtonClick:(UIButton *)button{

    if ([_delegate respondsToSelector:@selector(loginViewDidSelectButton:)]) {
        
        [_delegate loginViewDidSelectButton:button];
    }
    
}

//登陆按钮点击事件
- (void)loginButonClick:(UIButton *)button{

    if ([_delegate respondsToSelector:@selector(loginViewDidSelectButton:)]) {
        
        [_delegate loginViewDidSelectButton:button];
    }
}


@end
